const app = getApp()
const QQMapWX = require('./qqmap-wx-jssdk.min');
let qqmapsdk;

function getData(info) {
  wx.request({
    url: info.url,
    data: info.data,
    success: info.success,
    fail: info.fail,
    complete: info.complete
  })
}


// 实例化API核心类
qqmapsdk = new QQMapWX({
  key: app.globalData.txKey
});
//获取定位
function getPosition(info) {
  qqmapsdk.search({
    keyword: info.keyword,
    success: info.success,
    fail: info.fail,
    complete: info.complete
    // complete: function (res) {
    //   console.log(res);
    // }
  });
}

function searchPosition(info) {
  qqmapsdk.getSuggestion({
    keyword: info.keyword,
    success: info.success
  })
}

//获取时间
function getTime() {
  let date = new Date()
  let m = date.getMonth() + 1
  m = m == 12 ? 1 : m
  let day = date.getDate()
  let week = date.getDay()
  let arr = ['星期日','星期一','星期二','星期三','星期四','星期五','星期六']
  week = arr[week]

  return `${m}月${day}日${week}`
}

module.exports = {
  getData,
  getPosition,
  getTime,
  searchPosition
}